package com.donggua.aichebao.commonui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.donggua.aichebao.commonui.R;
/**
 * Created by Administrator on 2017-07-22.
 */
//com.donggua.aichebao.commonui.EvaluateLayout
public class EvaluateLayout extends LinearLayout{
    private ImageView[] imageList;
    private int margin = 1;
    private int PositiveSrc;
    private int ReverseSrc;
    private float Val;
    public EvaluateLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.Evaluate);
        this.setGravity(Gravity.CENTER_VERTICAL);
        this.margin = ta.getInt(R.styleable.Evaluate_evaluateMargin, 1);
        this.PositiveSrc = ta.getResourceId(R.styleable.Evaluate_evaluatePositiveSrc, R.mipmap.icon_star_fullx);
        this.ReverseSrc = ta.getResourceId(R.styleable.Evaluate_evaluateReverseSrc, R.mipmap.icon_star_emptyx);
        this.Val = ta.getFloat(R.styleable.Evaluate_evaluateVal, 3);
        init(context);
    }

    public EvaluateLayout(Context context) {
        super(context);
        init(context);
    }

    private void init(Context context) {
        this.setOrientation(LinearLayout.HORIZONTAL);
        imageList = new ImageView[5];
        LayoutParams layoutParams = new LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.leftMargin = this.margin;

        Drawable drawable = context.getResources().getDrawable(R.mipmap.ic_launcher);
        for (int i = 0; i < imageList.length; i++) {
            imageList[i] = new ImageView(context);
            imageList[i].setLayoutParams(layoutParams);
            if(i < this.Val)
            {
                imageList[i].setImageResource(this.PositiveSrc);
            }else
            {
                imageList[i].setImageResource(this.ReverseSrc);
            }
            this.addView(imageList[i]);
        }
        TextView textView = new TextView(context);
        textView.setText(" "+ String.valueOf(this.Val));
        this.addView(textView);
    }

    public void setEvaluate0(){

    }

    public void setEvaluate1(){

    }
    public void setEvaluate2(){

    }
    public void setEvaluate3(){

    }
    public void setEvaluate4(){

    }
    public void setEvaluate5(){

    }
}

